package 算法.十大排序算法;

import java.util.Arrays;

/**
 * @author coderFu
 * @create 2022/3/19
 * 选择排序
 */
public class CoderSelectSort {

    public static void main(String[] args) {
        int[] arr = new int[]{5,4,38,1};
        selectSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void selectSort(int[] arr){

        for(int i=0; i<arr.length; i++){
            int min = arr[i];
            int index = i;
            for(int j = i+1; j<arr.length; j++){
                if(arr[j]<min){
                    min = arr[j];
                    index = j;
                }
            }
            int temp = arr[i];
            arr[i] = arr[index];
            arr[index] = temp;
        }
    }
}
